﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MyCpuMonitor.Classes;
using MyCpuMonitor.Classes.WMI;

namespace MyCpuMonitor.Controls
{
    /// <summary>
    /// Interaction logic for ControlProcessorInfo.xaml
    /// </summary>
    public partial class ControlProcessorInfo
    {
        public int ProcessorNumber { get; set; }

        public ControlProcessorInfo(int processorNumber)
        {
            ProcessorNumber = processorNumber;
            InitializeComponent();

            ListBoxTemp.ItemsSource = CreateTemperatureInfo();
        }

        private System.Collections.IEnumerable CreateTemperatureInfo()
        {
            var c = new List<CpuInfoItem>();
            var pfdpop = new PerfFormattedDataPerfOsProcessor();

            c.Add(new CpuInfoItem {Name = "C1TransitionsPerSec", Value = pfdpop.C1TransitionsPerSec(ProcessorNumber)});
            c.Add(new CpuInfoItem {Name = "C2TransitionsPerSec", Value = pfdpop.C2TransitionsPerSec(ProcessorNumber)});
            c.Add(new CpuInfoItem {Name = "C3TransitionsPerSec", Value = pfdpop.C3TransitionsPerSec(ProcessorNumber)});
            c.Add(new CpuInfoItem { Name = "Caption", Value = pfdpop.Caption(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Description", Value = pfdpop.Description(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "DPCRate", Value = pfdpop.DPCRate(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "DPCsQueuedPerSec", Value = pfdpop.DPCsQueuedPerSec(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Frequency_Object", Value = pfdpop.Frequency_Object(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Frequency_PerfTime", Value = pfdpop.Frequency_PerfTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Frequency_Sys100NS", Value = pfdpop.Frequency_Sys100NS(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "InterruptsPerSec", Value = pfdpop.InterruptsPerSec(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Name", Value = pfdpop.Name(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentC1Time", Value = pfdpop.PercentC1Time(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentC2Time", Value = pfdpop.PercentC2Time(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentC3Time", Value = pfdpop.PercentC3Time(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentDPCTime", Value = pfdpop.PercentDPCTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentIdleTime", Value = pfdpop.PercentIdleTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentInterruptTime", Value = pfdpop.PercentInterruptTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentPrivilegedTime", Value = pfdpop.PercentPrivilegedTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentProcessorTime", Value = pfdpop.PercentProcessorTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "PercentUserTime", Value = pfdpop.PercentUserTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Timestamp_Object", Value = pfdpop.Timestamp_Object(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Timestamp_PerfTime", Value = pfdpop.Timestamp_PerfTime(ProcessorNumber) });
            c.Add(new CpuInfoItem { Name = "Timestamp_Sys100NS", Value = pfdpop.Timestamp_Sys100NS(ProcessorNumber) });


            return c;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ListBoxTemp.ItemsSource = CreateTemperatureInfo();
        }
    }
}
